package com.xiaoxx.common.error;




import com.xiaoxx.common.result.R;
import com.xiaoxx.common.result.RType;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;


/**
 * @author HX
 * @create 2022/2/25 15:38
 * @desc 自定义异常类
 **/
@Component
@Data
@NoArgsConstructor
public class ErrorException extends RuntimeException {

    private Integer code;
    private String msg;


    /**
     * @author HX
     * @create 2022/2/25 15:39
     * @desc 直接传递
     **/
    public ErrorException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * @author HX
     * @create 2022/2/25 15:39
     * @desc 枚举传递（建议先定义枚举）
     **/
    public ErrorException(RType RType) {
        this.code = RType.getValue();
        this.msg = RType.getMsg();
    }

    /**
     * @author  HX
     * @create  2022/2/25 15:40
     * @desc   枚举传递（建议先定义枚举）
     **/
    public <E> ErrorException(E e) {
        this.code = R.getEnumValue(e);
        this.msg = R.getEnumMsg(e);
    }
}
